﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Controls.Interfaces;
using Silvermoon.Controls.Base;

namespace Silvermoon.Controls.Classes
{
    public class DialogControlCollection : IList<Control>
    {
        private DialogBase owner;
        private ControlCollection collection;

        public DialogControlCollection(DialogBase owner)
            : base()
        {
            this.owner = owner;
            collection = new ControlCollection(owner);
        }

        #region IList<Control> Members

        public int IndexOf(Control item)
        {
            return collection.IndexOf(item);
        }

        public void Insert(int index, Control item)
        {
            collection.Insert(index, item);
        }

        public void RemoveAt(int index)
        {
            collection.RemoveAt(index);
        }

        public Control this[int index]
        {
            get { return collection[index]; }
            set { collection[index] = value; }
        }

        #endregion

        #region ICollection<Control> Members

        public void Add(Control item)
        {
            IDialogControl dlgCtrl = item as IDialogControl;
            if (dlgCtrl != null) dlgCtrl.Dialog = owner;
            collection.Add(item);
        }

        public void Clear()
        {
            collection.Clear();
        }

        public bool Contains(Control item)
        {
            return collection.Contains(item);
        }

        public void CopyTo(Control[] array, int arrayIndex)
        {
            collection.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return collection.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(Control item)
        {
            return collection.Remove(item);
        }

        #endregion

        #region IEnumerable<Control> Members

        public IEnumerator<Control> GetEnumerator()
        {
            return collection.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return collection.GetEnumerator();
        }

        #endregion
    }
}
